package com.knowswift.issues.mqtt.message;

import com.knowswift.issues.mqtt.MqttMessageUtil;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DeviceSetIntervalMessageHandler implements MqttMessageHandler {
    @Resource
    private MqttClient client;

    @Override
    public void handleMessage(String topic, MqttMessage message) {
        try {
            String downTopic = topic.replaceAll("/up", "/down");
            byte[] payload = new byte[0];

            client.publish(downTopic, payload, 1, true);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Byte supportMessageType() {
        return 0x05;
    }
}
